package com.icourt.learn.optional;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.Optional;

/**
 * 转换为 Optional
 */
@Slf4j
public class ToOptional {


    @Test
    public void test(){



        Optional<Double> x=inverse( 0.0 );
        x=Optional.ofNullable( null );
        double x1 =x.orElse( 22d );
        log.debug("返回值：{}",x1 );


    }


    public static Optional<Double> inverse(double x){

        return x==0? Optional.empty():Optional.of( 1/x );
    }
}
